<?php
class Silk_Zgb_Block_Page_Homepage extends Mage_Catalog_Block_Product_List
{
	protected $_categoryId = array(5,6,8,13,11,10,9,12);
	protected $_hotId = 14;

	public function getCatIds()
	{
		return $this->_categoryId;
	}

	protected function _getCatModel()
	{
		return Mage::getModel('catalog/category');
	}

	public function getCatUrl($id)
	{
		if(!$id) return false;
		return $this->_getCatModel()->load($id)->getUrl();
	}

	public function getCatName($id)
	{
		if(!$id) return false;
		return $this->_getCatModel()->load($id)->getName();
	}

	public function getCatImg($id)
	{
		if(!$id) return false;
		return $this->_getCatModel()->load($id)->getImageUrl();
	}

	public function getHotProduct()
	{
		return $this->_getCatModel()->load($this->_hotId)->getProductCollection()
			->addAttributeToSelect('*')
		    ->addWebsiteFilter(Mage::app()->getWebsite())
			->addAttributeToFilter('status', 1)
			->addAttributeToFilter('visibility', 4)
			->setOrder('position','ASC');
	}

	public function getCatProduct($id)
	{
		$size = 3;
		$_products = $this->_getCatModel()->load($id)->getProductCollection()
			->addAttributeToSelect('*')
		    ->addWebsiteFilter(Mage::app()->getWebsite())
			->addAttributeToFilter('status', 1)
			->addAttributeToFilter('visibility', 4)
			->setOrder('position','DESC');

		Mage::getSingleton('cataloginventory/stock')
    			->addInStockFilterToCollection($_products);

		$count = $_products->count();
		if($count >= 6){
			$size = 6;
		}
		
		$_products = $this->_getCatModel()->load($id)->getProductCollection()
			->addAttributeToSelect('*')
		    ->addWebsiteFilter(Mage::app()->getWebsite())
			->addAttributeToFilter('status', 1)
			->addAttributeToFilter('visibility', 4)
			->setOrder('position','DESC');

		Mage::getSingleton('cataloginventory/stock')
    			->addInStockFilterToCollection($_products);

		return $_products->setPage(1, $size);
	}
}